﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YFrameWork.RunTime.Tools;

namespace YFrameWork.RunTime
{
    public struct TypeNamePair: IEquatable<TypeNamePair>
    {
        private readonly Type m_type;
        private readonly string m_name;

        public TypeNamePair(Type _type) : this(_type, string.Empty)
        {

        }
        public TypeNamePair(Type _type,string _name)
        {
            if (_type == null)
            {
                throw new GameFrameworkException("传入的type是空的");
            }
            m_type = _type;
            m_name = _name ?? string.Empty;
        }

        public Type Type => m_type;

        public string Name => m_name;
        public override string ToString()
        {
            if (m_type == null)
            {
                throw new GameFrameworkException("type is Empty");
            }
            string typeName = m_type.FullName;
            return string.IsNullOrEmpty(m_name) ? typeName : Utility.Text.Format("{0},{1}", typeName, m_name);
        }
        public override int GetHashCode()
        {
            return m_type.GetHashCode() ^ m_name.GetHashCode();
        }

        /// <summary>
        /// 比较对象是否与自身相等。
        /// </summary>
        /// <param name="obj">要比较的对象。</param>
        /// <returns>被比较的对象是否与自身相等。</returns>
        public override bool Equals(object obj)
        {
            return obj is TypeNamePair && Equals((TypeNamePair)obj);
        }
        public bool Equals(TypeNamePair other)
        {
            return other.m_type == m_type && other.m_name == m_name;
        }
        /// <summary>
        /// 判断两个对象是否相等。
        /// </summary>
        /// <param name="a">值 a。</param>
        /// <param name="b">值 b。</param>
        /// <returns>两个对象是否相等。</returns>
        public static bool operator ==(TypeNamePair a, TypeNamePair b)
        {
            return a.Equals(b);
        }

        /// <summary>
        /// 判断两个对象是否不相等。
        /// </summary>
        /// <param name="a">值 a。</param>
        /// <param name="b">值 b。</param>
        /// <returns>两个对象是否不相等。</returns>
        public static bool operator !=(TypeNamePair a, TypeNamePair b)
        {
            return !(a == b);
        }
    }
}